#!/bin/bash

################################################################################
#    Download images from wikipedia filename                                   #
#                                                                              #
#                                                                              #
#    SOURCE CODE                                                               #
#                                                                              #
#    $filename = replace($name, ' ', '_');                                     #
#    $digest = md5($filename);                                                 #
#    $folder =                                                                 #
#        $digest[0] . '/' . $digest[0]                                         #
#        . $digest[1] . '/' .  urlencode($filename);                           #
#    $url = 'http://upload.wikimedia.org/wikipedia/commons/' . $folder;        #
#                                                                              #
#                                                                              #
#    EXAMPLE                                                                   #
#                                                                              #
#    WIKIPEDIA SOURCE CODE                                                     #
#    [[File:Basílica de Santiago 02.JPG|thumb|                                 #
#        upright|left|[[Santiago de Compostela Cathedral]]                     #
#                                                                              #
#    WIKIPEDIA LINK                                                            #
#   http://en.wikipedia.org/wiki/File:Basílica de Santiago 02.JPG              #
#                                                                              #
#    ./wikimage "Basílica de Santiago 02.JPG"                                  #    
#                                                                              #
################################################################################
filename1=$1
#Name already have passed with next change
#filename2=`echo $filename1 | sed 's/ /_/g'`
md5filename=`echo -n $filename1 | md5sum`
folder=${md5filename:0:1}'/'${md5filename:0:2}'/'$filename1
url='http://upload.wikimedia.org/wikipedia/commons/'$folder
wget -P ./epub_FILES/OEBPS/Images  $url 2> /dev/null
